<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sms extends OC_Controller {

	function __construct()
    {
        parent::__construct();
        $this->load->model('sms/sms_model','sm');
        $this->load->model('home/home_model');
        $this->load->model('events/events_model');
        $this->load->library('recaptcha');
    }

    function _remap($method, $params = array())
    {
        parent::_remap($method, $params);

        if (method_exists($this, $method))
            return call_user_func_array(array($this, $method), $params);
        else
            show_404();
    }

    function init_header()
    {
        $this->header['meta'] = array(
            'description' => array('name' => 'description', 'content' => 'Haan Kreasi Ibu Juara'),
            'keywords' => array('name' => 'keywords', 'content' => 'Haan Kreasi Ibu Juara, recipes, kreasi ibu, kreatif, sajian  kreatif'),
        );
    }

    function index()
	{
		$this->init_header();
		$this->header['nav'] = 'sms';
		$this->header['pagetitle'] = 'Sms Haan';
		$this->header['widget_home']    = $this->home_model->get_widget();
		$this->header['widget_footer']  = $this->home_model->get_widget(2);
		$this->header['recaptcha_html'] = $this->recaptcha->recaptcha_get_html();
		$this->header['socmed_home']    = $this->home_model->get_socmed();
		$this->header['get_cat_produk'] = $this->home_model->get_category('category_product','cp_id');
        $this->header['get_cat_resep']  = $this->home_model->get_category('category_recipes','cr_id');
        $this->header['get_cat_article']= $this->home_model->get_category('category_article','ca_id');
        $this->header['recent_articles']    = $this->events_model->get_recent_articles();
        $this->header['recent_products']    = $this->events_model->get_recent_products();
        $this->header['event_home']     = $this->home_model->get_event();	
		$this->view('sms/sms_view');
	}

	function do_reg()
	{
		$this->recaptcha->recaptcha_check_answer();
		if($this->input->post('submit') && $this->input->post('agree')=='on')
		{
			unset($_POST['recaptcha_challenge_field']);
			unset($_POST['recaptcha_response_field']);
			unset($_POST['submit']);
			unset($_POST['agree']);


			if($this->recaptcha->getIsValid()){
				$post['sms_created_date'] = date('Y-m-d H:i:s');
				$do_add = $this->sm->do_reg($this->input->post());
				if($do_add){
					redirect('sms/thanks', 'refresh');
				}else{
					redirect('sms');
				}
			}else{
				redirect('sms');
			}
		}
	}

	public function thanks()
	{
		$this->header['nav'] = 'sms';
		$this->header['pagetitle'] = 'Sms Haan';
		$this->header['widget_home']    = $this->home_model->get_widget();
		$this->header['socmed_home']    = $this->home_model->get_socmed();
		$this->header['get_cat_produk'] = $this->home_model->get_category('category_product','cp_id');
        $this->header['get_cat_resep']  = $this->home_model->get_category('category_recipes','cr_id');
        $this->header['get_cat_article']= $this->home_model->get_category('category_article','ca_id');
        $this->header['recent_articles']    = $this->events_model->get_recent_articles();
        $this->header['recent_products']    = $this->events_model->get_recent_products();
        $this->header['event_home']     = $this->home_model->get_event();
		$this->view('sms/thanks_view');
	}

}

/* End of file sms.php */
/* Location: ./applications/module_front/sms/controllers/sms.php */